import { defineStore } from 'pinia'
import { fetchRoutes } from '@/api'

export const useAuthStore = defineStore('auth', {
    state: () => ({
        hasRoutes: false,
        dynamicRoutes: []
    }),
    actions: {
        async fetchRoutes() {
            if (this.dynamicRoutes.length) return this.dynamicRoutes

            const routes = await fetchRoutes()
            this.dynamicRoutes = routes
            this.hasRoutes = true
            return routes
        },
        requiresAuth(to) {
            return !['/login', '/404'].includes(to.path)
        }
    }
})
